<template>
  <van-checkbox-group
    v-model="checked"
    v-bind="$attrs"
    :direction="props.direction"
    :icon-size="props.iconSize"
  >
    <template v-for="checkItem in props.options" :key="checkItem.value">
      <van-checkbox :name="checkItem.value">
        {{ checkItem.label }}
      </van-checkbox>
    </template>
  </van-checkbox-group>
</template>

<script setup lang="ts">
import { computed } from 'vue'

import type { CheckProps } from './props'

const props = withDefaults(defineProps<CheckProps>(), {
  modelValue: () => [],
  direction: 'horizontal',
  options: () => [],
  iconSize: () => 16
})

const emits = defineEmits({
  'update:modelValue': (val) => !!val
})

const checked = computed({
  get: () => {
    return props.modelValue
  },
  set: (val) => {
    emits('update:modelValue', val)
  }
})

defineOptions({
  name: 'VCheckBox'
})
</script>

<style scoped lang="scss">
:deep(.van-checkbox__label) {
  font-size: 16px;
}
</style>
